home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / REGEX.H < prev    next >
C/C++ Source or Header  |  1992-01-14  |  9KB  |  225 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/regex.h,v 1.5 1992/01/15 04:13:06 jinx Exp $
  4.  
  5. Copyright (c) 1987-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* NOTE: This program was created by translation from the regular
  36. expression code of GNU Emacs; it was translated from the original C to
  37. 68000 assembly language (in 1986), and then translated back from 68000
  38. assembly language to C (in 1987).  Users should be aware that the GNU
  39. GENERAL PUBLIC LICENSE may apply to this code.  A copy of that license
  40. should have been included along with this file. */
  41.  
  42. /* Structure to represent a buffer of text to match against.
  43.    This contains the information that an editor buffer would have
  44.    to supply for the matching process to be executed.
  45.  
  46.    `translation' is an array of MAX_ASCII characters which is used to
  47.    map each character before matching.  Both the pattern and the match
  48.    text are mapped.  This is normally used to implement case
  49.    insensitive searches.
  50.  
  51.    `syntax_table' describes the syntax of the match text.  See the
  52.    syntax table primitives for more information.
  53.  
  54.    `text' points to the beginning of the match text.  It is used only
  55.    for translating match text pointers into indices.
  56.  
  57.    `text_start' and `text_end' delimit the match text.  They define
  58.    the buffer-start and buffer-end for those matching commands that
  59.    refer to them.  Also, all matching must take place within these
  60.    limits.
  61.  
  62.    `gap_start' and `gap_end' delimit a gap in the match text.  Editor
  63.    buffers normally have such a gap.  For applications without a gap,
  64.    it is recommended that these be set to the same value as
  65.    `text_end'.
  66.  
  67.    Both `text_start' and `gap_start' are inclusive indices, while
  68.    `text_end' and `gap_end' are exclusive.
  69.  
  70.    The following conditions must be true:
  71.  
  72.    (text <= text_start)
  73.    (text_start <= text_end)
  74.    (gap_start <= gap_end)
  75.    (! ((text_start < text_end) &&
  76.        (gap_start < gap_end) &&
  77.        ((text_start == gap_start) || (text_end == gap_end))))
  78.  
  79.    */
  80.  
  81. struct re_buffer
  82.   {
  83.     unsigned char *translation;
  84.     SYNTAX_TABLE_TYPE syntax_table;
  85.     unsigned char *text;
  86.     unsigned char *text_start;
  87.     unsigned char *text_end;
  88.     unsigned char *gap_start;
  89.     unsigned char *gap_end;
  90.   };
  91.  
  92. /* Structure to store "register" contents data in.
  93.  
  94.    Pass the address of such a structure as an argument to re_match,
  95.    etc., if you want this information back.
  96.  
  97.    start[i] and end[i] record the string matched by \( ... \) grouping
  98.    i, for i from 1 to RE_NREGS - 1.
  99.  
  100.    start[0] and end[0] record the entire string matched. */
  101.  
  102. #define RE_NREGS 10
  103.  
  104. struct re_registers
  105.   {
  106.     long start[RE_NREGS];
  107.     long end[RE_NREGS];
  108.   };
  109.  
  110. /* These are the command codes that appear in compiled regular
  111.    expressions, one per byte.  Some command codes are followed by
  112.    argument bytes.  A command code can specify any interpretation
  113.    whatever for its arguments.  Zero-bytes may appear in the compiled
  114.    regular expression. */
  115.  
  116. enum regexpcode
  117.   {
  118.     regexpcode_unused,
  119.     regexpcode_exact_1,        /* Followed by 1 literal byte */
  120.  
  121.     /* Followed by one byte giving n, and then by n literal bytes. */
  122.     regexpcode_exact_n,
  123.  
  124.     regexpcode_line_start,    /* Fails unless at beginning of line */
  125.     regexpcode_line_end,    /* Fails unless at end of line */
  126.  
  127.     /* Followed by two bytes giving relative address to jump to. */
  128.     regexpcode_jump,
  129.  
  130.     /* Followed by two bytes giving relative address of place to
  131.        resume at in case of failure. */
  132.     regexpcode_on_failure_jump,
  133.  
  134.     /* Throw away latest failure point and then jump to address. */
  135.     regexpcode_finalize_jump,
  136.  
  137.     /* Like jump but finalize if safe to do so.  This is used to jump
  138.        back to the beginning of a repeat.  If the command that follows
  139.        this jump is clearly incompatible with the one at the beginning
  140.        of the repeat, such that we can be sure that there is no use
  141.        backtracking out of repetitions already completed, then we
  142.        finalize. */
  143.     regexpcode_maybe_finalize_jump,
  144.  
  145.     /* jump, and push a dummy failure point.  This failure point will
  146.        be thrown away if an attempt is made to use it for a failure.
  147.        A + construct makes this before the first repeat. */
  148.     regexpcode_dummy_failure_jump,
  149.  
  150.     regexpcode_any_char,    /* Matches any one character */
  151.  
  152.     /* Matches any one char belonging to specified set.  First
  153.        following byte is # bitmap bytes.  Then come bytes for a
  154.        bit-map saying which chars are in.  Bits in each byte are
  155.        ordered low-bit-first.  A character is in the set if its bit is
  156.        1.  A character too large to have a bit in the map is
  157.        automatically not in the set. */
  158.     regexpcode_char_set,
  159.  
  160.     /* Similar but match any character that is NOT one of those
  161.        specified. */
  162.     regexpcode_not_char_set,
  163.  
  164.     /* Starts remembering the text that is matched and stores it in a
  165.        memory register.  Followed by one byte containing the register
  166.        number.  Register numbers must be in the range 0 through
  167.        (RE_NREGS - 1) inclusive.  */
  168.     regexpcode_start_memory,
  169.  
  170.     /* Stops remembering the text that is matched and stores it in a
  171.        memory register.  Followed by one byte containing the register
  172.        number.  Register numbers must be in the range 0 through
  173.        (RE_NREGS - 1) inclusive.  */
  174.     regexpcode_stop_memory,
  175.  
  176.     /* Match a duplicate of something remembered.  Followed by one
  177.        byte containing the index of the memory register. */
  178.     regexpcode_duplicate,
  179.  
  180.     regexpcode_buffer_start,    /* Succeeds if at beginning of buffer */
  181.     regexpcode_buffer_end,    /* Succeeds if at end of buffer */
  182.     regexpcode_word_char,    /* Matches any word-constituent character */
  183.  
  184.     /* Matches any char that is not a word-constituent. */
  185.     regexpcode_not_word_char,
  186.  
  187.     regexpcode_word_start,    /* Succeeds if at word beginning */
  188.     regexpcode_word_end,    /* Succeeds if at word end */
  189.     regexpcode_word_bound,    /* Succeeds if at a word boundary */
  190.     regexpcode_not_word_bound,    /* Succeeds if not at a word boundary */
  191.  
  192.     /* Matches any character whose syntax is specified.  Followed by a
  193.        byte which contains a syntax code, Sword or such like. */
  194.     regexpcode_syntax_spec,
  195.  
  196.     /* Matches any character whose syntax differs from the specified. */
  197.     regexpcode_not_syntax_spec
  198.   };
  199.  
  200. extern void
  201.   EXFUN (re_buffer_initialize,
  202.      (struct re_buffer *, unsigned char *, SYNTAX_TABLE_TYPE,
  203.       unsigned char *, unsigned long, unsigned long,
  204.       unsigned long, unsigned long));
  205.  
  206. extern int
  207.   EXFUN (re_compile_fastmap,
  208.      (unsigned char *, unsigned char *, unsigned char *,
  209.       SYNTAX_TABLE_TYPE, unsigned char *));
  210.  
  211. extern int
  212.   EXFUN (re_match,
  213.      (unsigned char *, unsigned char *, struct re_buffer *,
  214.       struct re_registers *, unsigned char *, unsigned char *));
  215.  
  216. extern int
  217.   EXFUN (re_search_forward,
  218.      (unsigned char *, unsigned char *, struct re_buffer *,
  219.       struct re_registers *, unsigned char *, unsigned char *));
  220.  
  221. extern int
  222.   EXFUN (re_search_backward,
  223.      (unsigned char *, unsigned char *, struct re_buffer *,
  224.       struct re_registers *, unsigned char *, unsigned char *));
  225.